package com.bitdf.txing.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bitdf.txing.product.dao.SpuImagesDao;
import com.bitdf.txing.product.entity.SpuImagesEntity;
import com.bitdf.txing.product.service.SpuImagesService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;


@Service("spuImagesService")
public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesDao, SpuImagesEntity> implements SpuImagesService {

//    @Override
//    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<SpuImagesEntity> page = this.page(
//                new Query<SpuImagesEntity>().getPage(params),
//                new QueryWrapper<SpuImagesEntity>()
//        );
//
//        return new PageUtils(page);
//    }

    /**
     * 保存spu的图片集
     * @param id
     * @param images
     */
    @Override
    @Transactional
    public void saveImages(Long id, List<String> images) {
        if(images == null || images.size() == 0){
            return;
        }else{
            List<SpuImagesEntity> collect = images.stream().map(img -> {
                SpuImagesEntity spuImagesEntity = new SpuImagesEntity();
                spuImagesEntity.setSpuId(id);
                spuImagesEntity.setImgUrl(img);
                return spuImagesEntity;
            }).collect(Collectors.toList());
            this.saveBatch(collect);
        }
    }

}